$(function() {
  $(':button#wossnquery').bind('click', function() {
    $.getJSON('/_pagebywo', {
      wono: $("#main_won").text(),
      pageid: $("#spanPageNum").text(),
      date: new Date().getTime()+Math.random()
    }, function(data) {
      var curr = data.wonos;
      var lang = data.lang;
      createTable(curr, lang);
    });
    return false;
  });
})

function createTable(tableList, flags)
{
  var s = '';
  s += "<table id='tbl_ls' border='1' cellspacing='0' cellpadding='0'>";
  s += "<thead>";
  s += "<tr>";
  if(flags == "zh_CN") {
    s += "<th>索引</th>";
    s += "<th>产品序号</th>";
    s += "<th>站点</th>";
    s += "<th>结果</th>";
    s += "<th>不良代码</th>";  
  } else {
    s += "<th>Index</th>";
    s += "<th>Product No.</th>";
    s += "<th>Station</th>";
    s += "<th>Result</th>";
    s += "<th>Failcode</th>";
  } 
  s += "</tr>";
  s += "</thead>";
  s += "<tbody id='group_one'>";
  for(var idx in tableList)
  {
    if(idx%2 == 0)
    {
      s += "<tr class='alt-row'>";
    }
    else
    {
      s += "<tr class=''>"; 
    }
    if(tableList[idx].Result == 'PASS' || tableList[idx].Result == 'NDF')
    {
      s += "<td id='detail_idx' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px' width='80'>"+tableList[idx].Index+"</td>";
      s += "<td id='detail_ssn' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px' width='240'><a href='/queryssn?q="+tableList[idx].Serial+"'>"+tableList[idx].Serial+"</a></td>";
      s += "<td id='detail_sta' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px' width='300'>"+tableList[idx].Curr+"</td>";      
      s += "<td id='detail_rst' fieldset style='background: #00CC00; border-style: groove; font-weight: bold; font-size: 14px' width='100'>"+tableList[idx].Result+"</td>";
      s += "<td id='detail_fcd' fieldset style='color: #666666; border-style: groove; font-weight: bold; font-size: 14px' width='160'>"+tableList[idx].Failcode+"</td>";
    }
    else
    {
      s += "<td id='detail_idx' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px' width='80'>"+tableList[idx].Index+"</td>";
      s += "<td id='detail_ssn' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px' width='240'><a href='/queryssn?q="+tableList[idx].Serial+"'>"+tableList[idx].Serial+"</a></td>";
      s += "<td id='detail_sta' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px' width='300'>"+tableList[idx].Curr+"</td>";
      s += "<td id='detail_rst' fieldset style='background: #E00000; color: #EFF000; border-style: groove; font-weight: bold; font-size: 14px' width='100'>"+tableList[idx].Result+"</td>";
      s += "<td id='detail_fcd' fieldset style='background: #EFF000; border-style: groove; font-weight: bold; font-size: 14px' width='160'>"+tableList[idx].Failcode+"</td>";
    }
    s += "</tr>";
  }
  s += "</tbody>";
  s += "</table>";
  obj1.innerHTML = s;
}

function pagequery()
{
  wossnquery.click();
}